<?php

class Student_Model_DbTable_Scale extends Zend_Db_Table_Abstract
{

    protected $_name = "grade_scale";

       //this function is to fetch the row of given id. used to edit the scale table
         public function getScale($course_id)
        {
            $course_id = (int)$course_id;
            $row = $this->fetchRow('id_of_course = ' . $course_id);

            if (!$row)
                {
                    throw new Exception("Count not find row $course_id");
                }
            return $row->toArray();
        }

        public function getAllScale($course_id)
        {
            $course_id = (int)$course_id;
            $row = $this->fetchAll('id_of_course = ' . $course_id);

            if (!$row)
                {
                    throw new Exception("Count not find row $course_id");
                }
            return $row->toArray();
        }

        //this function is to fetch everything from the table with given id
        public function getCourseScale($course_id)
        {
            $course_id = (int)$course_id;
            $row = $this->fetchAll('id_of_course = ' . $course_id);

            if (!$row)
                {
                    throw new Exception("Count not find row $course_id");
                }
            return $row;
        }

        public function getScaleDetails($scale_id)
        {
            $scale_id = (int)$scale_id;
            $row = $this->fetchAll('id = ' . $scale_id);
            if (!$row)
            {
                    throw new Exception("Count not find row $scale_id");
             }
            return $row;
        }
        
        public function addScale($id_of_course, $grade, $minimum, $maximum)
        {

		$data = array (
                 'id_of_course' => $id_of_course,
		 'grade' => $grade,
                 'minimum' => $minimum,
                 'maximum' => $maximum


		);
		$this->insert($data);
	}

        public function editScale($id, $minimum, $maximum, $grade)
        {
            $data = array (
                 'id_of_course' => $id,
		 'minimum' => $minimum,
                 'maximum' => $maximum,
                 'grade' => $grade,

		);

            $this->update($data, 'id = '. (int)$id);
        }

        

        public function deleteScale($id)
        {
            $this->delete('id_of_course =' . (int)$id);
        }
}